package com.cjm.algorithm;

import com.cjm.algorithm.babo.Babo;
import com.cjm.algorithm.babo.InsertSort;
import com.cjm.algorithm.babo.SelectSort;
import com.cjm.algorithm.babo.ShellSort;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

public class GeneratorUtils {
    private static final int num = 20000;
    private static final int start = 2;
    private static final int end = start + num;

    public static void main(String[] args) {
        long l = System.currentTimeMillis();
        Babo.babo();
        SelectSort.selectSort();
        InsertSort.insertSort();
        ShellSort.shellSort();
        long l1 = System.currentTimeMillis();
        System.err.println("总共花了" + (l1 - l) + "ms");
    }


    public static final AtomicInteger count = new AtomicInteger(0);
    public static int[] originArray;

    public static int[] generator() {
        if (originArray == null) {
            originArray = generator(num, start, end);
        }
        int[] arr = new int[num];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = originArray[i];
        }
        return arr;
    }

    public static int[] generator(int num, int start, int end) {
        int[] arr = new int[num];

        for (int i = 0; i < num; i++)
            arr[i] = (int)(Math.random() * (end - start + 1) + start);
        return arr;
    }

    public static void print(int[] arr) {
        check(arr);
//        print("总共交换了" + count.get() + "次.");
    }

    public static void check(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] > arr[i + 1]) {
                System.err.println("排序失败");
                print("=================xxxxx============>排序失败");
                return;
            }
        }
        print("=================√√√√√============>排序正确");
    }

    public static void swap(int[] arr, int start, int end) {
        int temp = arr[start];
        arr[start] = arr[end];
        arr[end] = temp;
//        count.getAndIncrement();
    }

    private static void print(String msg) {
        System.out.println("<=================================>");
        System.out.println(msg);
        System.out.println("<=================================> \r\n");
    }
}
